<template>
	<view class="">
		<view class="status_bar"></view>
		<view class="content">
			<view class="inputBox f-c-b" @click="$to(`../toSearch/toSearch`)">
				<image src="../../static/index/icon_search.png" mode="widthFix"></image>
				<input type="text" placeholder="搜索商品" placeholder-class="placla" />
				<text>搜索</text>
			</view>

			<!-- 轮播图 -->
			<view class="swiper">
				<u-swiper @click="rotationDetail" :list="list" height='290'>
				</u-swiper>
			</view>

			<!-- 特价商品 -->
			<view class="recommend">
				<view class="recommendTitle f35">特价商品</view>
				<view class="recommendAll">
					<view v-for="(item,index) in commodityList" class="recommendItem f-c"
						@click="$to(`../product_detail/product_detail`)">
						<view class="recommendItem-img f-c-c">
							<image :src="item.image" mode="widthFix"></image>
						</view>
						<view class="recommendItem-img-info f-c-b f30 fw">
							<view>{{item.title}}</view>
							<view class="f35">￥{{item.price}}</view>
						</view>
						<view class="f-c-a f25">
							<view>库存：{{item.stock}}</view>
							<view>浏览：{{item.browse}}</view>
						</view>
						<view class="buy f-c-a f25">
							<view style="color:#999999">原价：<del>￥100.00</del></view>
							<view class="toBuy">抢购</view>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: [],
				commodityList: [{
					image: '../../static/index/img_sp.png',
					title: '红木',
					stock: 515,
					browse: 200,
					likeFlag: false,
					price: 20
				}, {
					image: '../../static/index/img_sp2.png',
					title: '红木',
					stock: 515,
					browse: 200,
					likeFlag: true,
					price: 100
				}]
			}
		},
		onLoad() {
			this.rotationInfo()
		},
		methods: {
			async rotationInfo() {
				const { data, success, msg } = await this.$u.api.rotationInfo()
				console.log(data);
				console.log(success);
				console.log(msg);
				data.forEach(item => {
					if (item.rtype == 2) {
						this.list.push({
							image: this.$u.baseUrl + item.rcoverimg,
							id: item.id
						})
					}
				});
				console.log(this.list);
			},
			rotationDetail(i) {
				this.$to(`../index_carouselDetails/index_carouselDetails?id=${this.list[i].id}`)
			}
		}
	}
</script>

<style>
	.content {
		background-color: #F4F4F4;
		height: 100vh;
		padding: 20rpx;
	}

	.inputBox {
		background-color: #FFFFFF;
		border-radius: 10rpx;
	}

	.inputBox image {
		width: 30rpx;
		margin-left: 20rpx;
	}

	.inputBox text {
		background-color: #FF8710;
		color: #FFFFFF;
		padding: 15rpx 20rpx;
		border-radius: 0 10rpx 10rpx 0;
	}

	.inputBox input {
		margin-left: -150rpx;
	}

	.placla {
		font-size: 30rpx;
		color: #999999
	}

	.swiper {
		padding: 20rpx 0;
	}

	.recommendTitle {
		font-weight: 700;
	}

	.recommendItem-img image {
		width: 300rpx;
		margin: 20rpx 0;
	}

	.recommendItem {
		background-color: #FFFFFF;
		width: 340rpx;
		margin: 6rpx;
		position: relative;
	}

	.recommendItem-img-info {
		margin: 0 20rpx 10rpx 20rpx;
		border-bottom: 1rpx solid #EEEEEE;
		padding-bottom: 10rpx;
	}

	.recommendItem-img-info view:nth-child(2) {
		color: #FF2929;
	}

	.recommendAll {
		display: flex;
		flex-wrap: wrap;
		justify-content: space-between;
	}

	.toBuy {
		background-color: #FF8710;
		color: #FFFFFF;
		padding: 5rpx 15rpx;
		border-radius: 18rpx;
	}

	.buy {
		margin-top: 10rpx;
	}
</style>
